let btn = document.getElementById('btn1');
btn.onclick = function () {
    btn.disabled = true;  //当点击后倒计时时候不能点击此按钮 
    let time = 20;  //倒计时5秒 
    let timer = setInterval(fun1, 1000);  //设置定时器 
    function fun1() {
        time--;
        if (time >= 0) {
            btn.innerHTML = time + "s后重新发送";
        } else {
            btn.innerHTML = "重新发送验证码";
            btn.disabled = false;  //倒计时结束能够重新点击发送的按钮 
            clearInterval(timer);  //清除定时器 
            time = 20;  //设置循环重新开始条件 
        }
    }
}
$(function () {  
    $("#btn2").click(function () {       
        //判断手机号的格式
        let phone = document.querySelector("input[name='phone']");
        if (!/^1[3578]\d{9}$/.test(phone.value)) {
            phone.setCustomValidity("要符合手机号码的格式");
        } else {
            phone.setCustomValidity("");
        }
        //判断验证码的格式
        let yanzheng = document.querySelector("input[name='yanzheng']");
        if (!/\w{6}/.test(yanzheng.value)) {
           yanzheng.setCustomValidity("请输入六位数的验证码");
        } else {
            yanzheng.setCustomValidity("");
        }
        //判断密码的格式
        let password = document.querySelector("input[name='password']");
        if (!/\w{6,10}/.test(password.value)) {
            password.setCustomValidity("密码应为6~10位的字符");
        } else {
            password.setCustomValidity("");
        }
        //判断再次输入密码的格式
        let repassword = document.querySelector("input[name='password']");
        if (!/\w{6,10}/.test(repassword.value)) {
            repassword.setCustomValidity("密码应为6~10位的字符");
        } else {         
            repassword.setCustomValidity("");      
       }
    })
});
